package model;

import java.io.Serializable;
import java.util.HashMap;

import com.lynden.gmapsfx.javascript.object.LatLong;

public class City implements Serializable
{
	private String name;
	private String party;
	private String department;
	private String region;
	private String statut;
	private long population;
	private double lat;
	private double lon;
	private transient LatLong latLong;
	private boolean inChart;
	private HashMap<String, Double> rates = new HashMap<String, Double>();
	
	@Override
	public String toString() 
	{
		return name + "\t" + rates;
	}
	
	public boolean isInChart() {
		return inChart;
	}

	public void setInChart(boolean inChart) {
		this.inChart = inChart;
	}

	public void putRate(String n, Double v)
	{
		rates.put(n, v);
	}
	
	public Double getRate(String n) {
		return rates.get(n);
	}
	
	public Double getRate(String name, int year, int round)
	{
		return rates.get(name + "_" + Integer.toString(year) + "_" + Integer.toString(round));
	}
	
	public boolean hasBothRates(String name, int round)
	{
		return rates.get(name + "_2001_" + Integer.toString(round))!=null 
		    && rates.get(name + "_2008_" + Integer.toString(round))!=null;
	}
	
	public City(String name, String party, String department, String region,
			    String statut, double population, LatLong latLong) 
	{
		super();
		this.name = name;
		this.party = party;
		this.department = department;
		this.region = region;
		this.statut = statut;
		this.population = Math.round(population * 1000);
		this.latLong = latLong;
		this.lat = latLong.getLatitude();
		this.lon = latLong.getLongitude();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getParty() {
		return party;
	}
	public void setParty(String party) {
		this.party = party;
	}
	public double getLat() {
		return lat;
	}
	public void setLat(double lat) {
		this.lat = lat;
	}
	public double getLon() {
		return lon;
	}
	public void setLon(double lon) {
		this.lon = lon;
	}
	public String getDepartment() {
		return department;
	}
	public void setDepartment(String department) {
		this.department = department;
	}
	public String getRegion() {
		return region;
	}
	public void setRegion(String region) {
		this.region = region;
	}
	public String getStatut() {
		return statut;
	}
	public void setStatut(String statut) {
		this.statut = statut;
	}
	public long getPopulation() {
		return population;
	}
	public void setPopulation(long population) {
		this.population = population;
	}
	
	public LatLong getLatLong()
	{
		if (latLong==null)
			latLong = new LatLong(this.getLat(), this.getLon());
		
		return latLong;
	}
}
